import java.util.ArrayList;
import java.util.List;

public class Solution {
    public static void main(String[] args) {
        Solution s = new Solution();
        int[][] a = new int[][]{{1, 2, 4}, {3, 3, 1}};
        int i = s.deleteGreatestValue(a);
        System.out.println("sum :" + i);
    }

    int temp = 0;
    int tempMax = 0;
    int tempIndex = 0;
    int result = 0;

    public int deleteGreatestValue(int[][] grid) {
        if (grid == null) return 0;
        for (int i = 0; i < grid.length; i++) {
            temp = 0;
            if (grid[i] != null && grid[i].length > 0) {
                grid[i] = newIntArr(grid[i]);
                System.out.println("本次循环最大 " + temp);
                if (tempIndex != grid.length) {
                    tempIndex++;
                    System.out.println("索引数++");
                    if (tempMax <= temp) {
                        tempMax = temp;
                    }
                }
                if (tempIndex == grid.length) {
                    System.out.println("取得最大循环数 " + tempMax);
                    result += tempMax;
                    tempMax = 0;
                    System.out.println("索引归零");
                    tempIndex = 0;
                }


            } else {
                grid = null;
            }

        }
        System.out.println(grid);
        if (grid != null && grid.length > 0 && grid[0] != null) {
            deleteGreatestValue(grid);
        }

        return result;
    }

    public int[] newIntArr(int[] grid) {
        int iMax = 0;
        for (int j = 0; j < grid.length; j++) {
            if (grid[j] > iMax) {
                iMax = grid[j];
            }
        }
        if (grid.length > 1) {
            int[] r = new int[grid.length - 1];
            int index = 0;
            boolean hasMax = false;
            for (int i = 0; i < grid.length; i++) {
                int y = grid[i];
                if (iMax == y && hasMax == false) {
                    hasMax = true;
                    continue;
                }
                r[index] = y;
                index++;
            }
            if (iMax > temp) {
                temp = iMax;
            }
            return r;

        } else {
            if (grid.length > 0) {
                temp = grid[0];
                if (iMax > temp) {
                    temp = iMax;
                }
            }

            return null;
        }

    }

}
